#!/usr/bin/wish -f
#
# Copyright (c) 2020 NVI, Inc.
#
# This file is part of VLBI Field System
# (see http://github.com/nvi-inc/fs).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

set read 1
set logfile_name [lindex $argv 0]

 if {[file exists /usr2/log/$logfile_name]} {
  set file [open /usr2/log/$logfile_name r]
 } else {
  puts "Error, can't find file /usr2/log/$logfile_name"
   while {$read==1} {
    # Do nothing.
   }
 }

puts "Starts processing $logfile_name until EOF.."

while {[eof $file] != 1} {
  set line [gets $file]
  puts $line 
  after 2   
}

puts "Finished processing $logfile_name until EOF, Waiting for new input."


while {$read==1} {
 if {[gets $file line] >= 0} {
  puts $line 
  after 2   
 } else {
  after 10
 }
}
close $file
